package com.opgea.crm.web.controller;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.opgea.crm.common.constant.ApplicationConstant;
import com.opgea.crm.domain.modal.JsonModelMap;


@Controller
@RequestMapping("login")
public class LoginController {


	@RequestMapping(method=RequestMethod.GET)
	public String show(HttpServletRequest request){
		HttpSession session = request.getSession();
		Object obj = session.getAttribute(ApplicationConstant.SESSION_USER_DETAILS);
		String targetPage = "login";
		if(obj != null){
			targetPage = "redirect: header";
		}
		return targetPage;
	}
	
	
	@RequestMapping(method=RequestMethod.GET, value="logout")
	public @ResponseBody Map<String, Object> logout(HttpServletRequest request){
		System.out.println("Logout...");
		HttpSession session = request.getSession();
		session.invalidate();
		return JsonModelMap.success().data("Logout");
	}
}
